<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Hash;
use DB;
class LoginController extends Controller
{  
    // 用户登录页面
   public function getIndex(){
      if(session('web') == 2){
        // 关闭状态
        $webconfig = DB::table('webconfig') -> first();
        return view('home/webconfig/index',['webconfig'=> $webconfig]);
       }else{
         return view('home/login/index');
       }
   
   }
   //用户验证登录
   public function postLogin(Request $request){
    // 表单验证  
    
  	$this->validate($request,[
    	'email'=>'required',
    	'password'=>'required'

	
	],[
		'email.required'=>'请输入手机号|用户名|邮箱',
		'password.required'=>'请输入密码',
	]);
    //$email 手机号 邮箱 用户名
  $email = $request -> only('email');

  $data = DB::table('user') -> where('email',$email['email'])->orwhere('tel',$email['email'])->orwhere('username',$email['email'])-> first();
  // dd($data);
  // 查看是否激活 2为激活
  if($data['disable'] == 1){

    return back() -> with('error','请激活账号');
  }
  // 验证密码
  if (Hash::check($request -> input('password'),$data['password'])) {
     session(['id'=>$data['id']]); 
    return redirect('/home'); 
}else{
    return back() -> with('error','登录失败,密码不正确');

}

   }
}
